package com.koron.system.redis;

import com.alibaba.fastjson.JSON;
import com.koron.bean.app.AppBean;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @ClassName RedisPublisher
 * @description
 * @Author zhouj
 * @Date 2021/10/20 16:33
 */
@Slf4j
@Component
public class RedisPublisher {

    @Autowired
    StringRedisTemplate redisTemplate;

    public void publish(AppBean appBean) {

        try {
            if (StringUtils.isEmpty(appBean.getMark())) {
                log.error("数据源标识为空");
                return;
            }
            redisTemplate.convertAndSend("channel-dynamicDs", JSON.toJSONString(appBean));
        } catch (Exception ex) {
            log.error("发布消息到redis失败 {}", ex.getMessage());
        }

    }

}
